package com.ymq.modle;

import com.ymq.view.BackgroundImage;

import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;

import javax.imageio.ImageIO;




public class Obstacle {
    public int x, y;// 横纵坐标
    public BufferedImage image;
    private BufferedImage stone;// 石头图片
    private BufferedImage cacti;// 仙人掌图片
    private int speed;// 移动速度

    public Obstacle() {
        try {
            stone = ImageIO.read(new File("image/石头.png"));
            cacti = ImageIO.read(new File("image/仙人掌.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        Random r = new Random();//
        if (r.nextInt(2) == 0) {//
            image = cacti;//
        } else {
            image = stone;//
        }
        x = 800;//
        y = 200 - image.getHeight();//
        speed = BackgroundImage.SPEED;//
    }

    public void move() {
        x -= speed;//
    }

    /**
     * ??????
     * 
     * @return
     */
    public Rectangle getBounds() {
        if (image == cacti) {//
            //
            return new Rectangle(x + 7, y, 15, image.getHeight());
        }
        //
        return new Rectangle(x + 5, y + 4, 23, 21);
    }


    public boolean isLive() {
        //
        if (x <= -image.getWidth()) {
            return false;//
        }
        return true;//
    }
}
